// import { defineConfig } from 'vite'
// import react from '@vitejs/plugin-react'
// import tailwindcss from '@tailwindcss/vite'

// // https://vite.dev/config/
// export default defineConfig({
//   plugins: [react(), tailwindcss()],
// })
/*
 * @Author: LeeZB
 * @Date: 2025-02-19 18:44:15
 * @LastEditors: Leezb101 leezb101@126.com
 * @LastEditTime: 2025-03-07 15:45:25
 * @copyright: Copyright © 2025 高新供水.
 */
import { defineConfig, loadEnv, ConfigEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import tailwindcss from '@tailwindcss/vite'

// https://vite.dev/config/
export default defineConfig(({ mode }: ConfigEnv) => {
  const env = loadEnv(mode, process.cwd())
  return {
    base: './',
    plugins: [react(), tailwindcss()],
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        '@/components': resolve(__dirname, './src/components'),
        '@/assets': resolve(__dirname, './src/assets'),
        '@/utils': resolve(__dirname, './src/utils'),
        '@/api': resolve(__dirname, './src/api'),
        '@/pages': resolve(__dirname, './src/pages'),
        '@/store': resolve(__dirname, './src/store'),
      },
    },
    server: {
      port: Number(env.VITE_APP_PORT),
      open: true,
      cors: true,
      host: 'localhost',
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_APP_API_URL,
          changeOrigin: true,
          rewrite: (pth) =>
            pth.replace(new RegExp(`^${env.VITE_APP_BASE_API}`), ''),
        },
      },
    },
  }
})
